

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Discovery techniques &mdash; geoslurp v1.1.0 documentation</title>
  

  
  
    <link rel="shortcut icon" href="../_static/favicon.ico"/>
  
  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  

  

  
        <link rel="index" title="Index"
              href="../genindex.html"/>
        <link rel="search" title="Search" href="../search.html"/>
    <link rel="top" title="geoslurp v1.1.0 documentation" href="../index.html"/>
        <link rel="up" title="Python Examples" href="pyexamples.html"/>
        <link rel="next" title="Exporting parts of the database to portable formats" href="export2Portable.html"/>
        <link rel="prev" title="Download and register a dynamic dataset of (crowd-sourced?) US Marijuana street prices" href="CreateDynDSet.html"/> 

  
  <script src="../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../index.html" class="icon icon-home"> geoslurp
          

          
          </a>

          
            
            
              <div class="version">
                1.1.0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../introduction.html">An introduction to Geoslurp</a></li>
<li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation of the geoslurp package and setting up the PostgreSQL instance</a></li>
<li class="toctree-l1"><a class="reference internal" href="../confsettings.html">Configuration</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../examples.html">Tutorial</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../usingcli.html">Using the command line tool geoslurp</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="pyexamples.html">Python Examples</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="connectnQuery.html">Establish a database connection and retrieve the inventory and User settings</a></li>
<li class="toctree-l3"><a class="reference internal" href="UsingCataloguedDsets.html">Downloading and registering “catalogue” datasets</a></li>
<li class="toctree-l3"><a class="reference internal" href="CreateDynDSet.html">Download and register a dynamic dataset of (crowd-sourced?) US Marijuana street prices</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">Discovery techniques</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#Query-a-single-table-and-visualize-the-result">Query a single table and visualize the result</a></li>
<li class="toctree-l4"><a class="reference internal" href="#A-more-complicated-query-which-joins-data-between-tables">A more complicated query which joins data between tables</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="export2Portable.html">Exporting parts of the database to portable formats</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../reference.html">Reference Documentation</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">geoslurp</a>
        
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../examples.html">Tutorial</a> &raquo;</li>
        
          <li><a href="pyexamples.html">Python Examples</a> &raquo;</li>
        
      <li>Discovery techniques</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../_sources/examples/BasicDiscovery.ipynb.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  
<style>
/* CSS for nbsphinx extension */

/* remove conflicting styling from Sphinx themes */
div.nbinput,
div.nbinput div.prompt,
div.nbinput div.input_area,
div.nbinput div[class*=highlight],
div.nbinput div[class*=highlight] pre,
div.nboutput,
div.nbinput div.prompt,
div.nbinput div.output_area,
div.nboutput div[class*=highlight],
div.nboutput div[class*=highlight] pre {
    background: none;
    border: none;
    padding: 0 0;
    margin: 0;
    box-shadow: none;
}

/* avoid gaps between output lines */
div.nboutput div[class*=highlight] pre {
    line-height: normal;
}

/* input/output containers */
div.nbinput,
div.nboutput {
    display: -webkit-flex;
    display: flex;
    align-items: flex-start;
    margin: 0;
    width: 100%;
}
@media (max-width: 540px) {
    div.nbinput,
    div.nboutput {
        flex-direction: column;
    }
}

/* input container */
div.nbinput {
    padding-top: 5px;
}

/* last container */
div.nblast {
    padding-bottom: 5px;
}

/* input prompt */
div.nbinput div.prompt pre {
    color: #303F9F;
}

/* output prompt */
div.nboutput div.prompt pre {
    color: #D84315;
}

/* all prompts */
div.nbinput div.prompt,
div.nboutput div.prompt {
    min-width: 8ex;
    padding-top: 0.4em;
    padding-right: 0.4em;
    text-align: right;
    flex: 0;
}
@media (max-width: 540px) {
    div.nbinput div.prompt,
    div.nboutput div.prompt {
        text-align: left;
        padding: 0.4em;
    }
    div.nboutput div.prompt.empty {
        padding: 0;
    }
}

/* disable scrollbars on prompts */
div.nbinput div.prompt pre,
div.nboutput div.prompt pre {
    overflow: hidden;
}

/* input/output area */
div.nbinput div.input_area,
div.nboutput div.output_area {
    padding: 0.4em;
    -webkit-flex: 1;
    flex: 1;
    overflow: auto;
}
@media (max-width: 540px) {
    div.nbinput div.input_area,
    div.nboutput div.output_area {
        width: 100%;
    }
}

/* input area */
div.nbinput div.input_area {
    border: 1px solid #cfcfcf;
    border-radius: 2px;
    background: #f7f7f7;
}

/* override MathJax center alignment in output cells */
div.nboutput div[class*=MathJax] {
    text-align: left !important;
}

/* override sphinx.ext.pngmath center alignment in output cells */
div.nboutput div.math p {
    text-align: left;
}

/* standard error */
div.nboutput div.output_area.stderr {
    background: #fdd;
}

/* ANSI colors */
.ansi-black-fg { color: #3E424D; }
.ansi-black-bg { background-color: #3E424D; }
.ansi-black-intense-fg { color: #282C36; }
.ansi-black-intense-bg { background-color: #282C36; }
.ansi-red-fg { color: #E75C58; }
.ansi-red-bg { background-color: #E75C58; }
.ansi-red-intense-fg { color: #B22B31; }
.ansi-red-intense-bg { background-color: #B22B31; }
.ansi-green-fg { color: #00A250; }
.ansi-green-bg { background-color: #00A250; }
.ansi-green-intense-fg { color: #007427; }
.ansi-green-intense-bg { background-color: #007427; }
.ansi-yellow-fg { color: #DDB62B; }
.ansi-yellow-bg { background-color: #DDB62B; }
.ansi-yellow-intense-fg { color: #B27D12; }
.ansi-yellow-intense-bg { background-color: #B27D12; }
.ansi-blue-fg { color: #208FFB; }
.ansi-blue-bg { background-color: #208FFB; }
.ansi-blue-intense-fg { color: #0065CA; }
.ansi-blue-intense-bg { background-color: #0065CA; }
.ansi-magenta-fg { color: #D160C4; }
.ansi-magenta-bg { background-color: #D160C4; }
.ansi-magenta-intense-fg { color: #A03196; }
.ansi-magenta-intense-bg { background-color: #A03196; }
.ansi-cyan-fg { color: #60C6C8; }
.ansi-cyan-bg { background-color: #60C6C8; }
.ansi-cyan-intense-fg { color: #258F8F; }
.ansi-cyan-intense-bg { background-color: #258F8F; }
.ansi-white-fg { color: #C5C1B4; }
.ansi-white-bg { background-color: #C5C1B4; }
.ansi-white-intense-fg { color: #A1A6B2; }
.ansi-white-intense-bg { background-color: #A1A6B2; }

.ansi-default-inverse-fg { color: #FFFFFF; }
.ansi-default-inverse-bg { background-color: #000000; }

.ansi-bold { font-weight: bold; }
.ansi-underline { text-decoration: underline; }

/* CSS overrides for sphinx_rtd_theme */

/* 24px margin */
.nbinput.nblast,
.nboutput.nblast {
    margin-bottom: 19px;  /* padding has already 5px */
}

/* ... except between code cells! */
.nblast + .nbinput {
    margin-top: -19px;
}

.admonition > p:before {
    margin-right: 4px;  /* make room for the exclamation icon */
}
</style>
<div class="section" id="Discovery-techniques">
<h1>Discovery techniques<a class="headerlink" href="#Discovery-techniques" title="Permalink to this headline">¶</a></h1>
<p>Querying the database can be done with anything which support attaching
to a PostGreSQL database. Many interface libraries for a variety of
programming languages exist, so this is in the end a user’s choice.</p>
<p>That being said, often there are queries which need to be done more
often, and it pays off to build convenience functions which wrap a
database query. Commonly used query wrapper are found in the <a class="reference external" href="../reference/geoslurp.discover.html#module-geoslurp.discover">discover
subdirectory</a>.</p>
<p>Below are a few examples which demonstrate the use of sqlalchemy to
perform queries. They make use of the data which has been registered in
<a class="reference external" href="../examples/CreateDynDSet.html#Download-and-register-a-dataset-of-(fictious?)-US-Marijuana-street-prices">this
notebook</a>.
The queries are encapsulated in functions which return an iteratable
object which is the result of the query. This is also the same pattern
as most functions in the <em>discover</em> directory obey.</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre>
<span></span>In [1]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">geoslurp.config</span> <span class="k">import</span> <span class="n">setInfoLevel</span>
<span class="kn">from</span> <span class="nn">geoslurp.db</span> <span class="k">import</span> <span class="n">geoslurpConnect</span>
<span class="n">setInfoLevel</span><span class="p">()</span>

<span class="n">gpcon</span><span class="o">=</span><span class="n">geoslurpConnect</span><span class="p">()</span> <span class="c1"># this will be a connection based on the readonly user</span>
</pre></div>
</div>
</div>
<div class="section" id="Query-a-single-table-and-visualize-the-result">
<h2>Query a single table and visualize the result<a class="headerlink" href="#Query-a-single-table-and-visualize-the-result" title="Permalink to this headline">¶</a></h2>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre>
<span></span>In [2]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="k">import</span> <span class="n">select</span><span class="p">,</span><span class="n">asc</span>
<span class="k">def</span> <span class="nf">queryState</span><span class="p">(</span><span class="n">dbcon</span><span class="p">,</span><span class="n">state</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Query the usweedprices2 table for a given state, while sorting the results according to their timestamp&quot;&quot;&quot;</span>
    <span class="c1">#retrieve/reflect the table (note the lowercase table name)</span>
    <span class="n">tbl</span><span class="o">=</span><span class="n">dbcon</span><span class="o">.</span><span class="n">getTable</span><span class="p">(</span><span class="s1">&#39;usweedprices2&#39;</span><span class="p">,</span><span class="s1">&#39;public&#39;</span><span class="p">)</span>

    <span class="n">qry</span><span class="o">=</span><span class="n">select</span><span class="p">([</span><span class="n">tbl</span><span class="p">])</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">tbl</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">State</span> <span class="o">==</span> <span class="n">state</span><span class="p">)</span><span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="n">asc</span><span class="p">(</span><span class="n">tbl</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">date</span><span class="p">))</span>

    <span class="k">return</span> <span class="n">dbcon</span><span class="o">.</span><span class="n">dbeng</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">qry</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="Pick-a-state-and-plot-the-results-using-matplotlib">
<h3>Pick a state and plot the results using matplotlib<a class="headerlink" href="#Pick-a-state-and-plot-the-results-using-matplotlib" title="Permalink to this headline">¶</a></h3>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre>
<span></span>In [3]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">mpl</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">datetime</span>
<span class="o">%</span><span class="k">matplotlib</span> inline

<span class="n">statename</span><span class="o">=</span><span class="s2">&quot;California&quot;</span>

<span class="n">t</span><span class="o">=</span><span class="p">[]</span>
<span class="n">medq</span><span class="o">=</span><span class="p">[]</span>
<span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="n">queryState</span><span class="p">(</span><span class="n">gpcon</span><span class="p">,</span><span class="n">statename</span><span class="p">):</span>
    <span class="n">t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">entry</span><span class="o">.</span><span class="n">date</span><span class="p">,</span> <span class="s2">&quot;%Y-%m-</span><span class="si">%d</span><span class="s2">&quot;</span><span class="p">))</span>
    <span class="n">medq</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">entry</span><span class="o">.</span><span class="n">MedQ</span><span class="p">)</span>


<span class="n">fig</span><span class="p">,</span><span class="n">ax</span><span class="o">=</span><span class="n">mpl</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span>
<span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span><span class="n">medq</span><span class="p">)</span>
<span class="n">mpl</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s2">&quot;USD&quot;</span><span class="p">)</span>
<span class="n">mpl</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> Medium quality Street price Marijuana&quot;</span><span class="o">%</span><span class="k">statename</span>)
<span class="n">mpl</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s2">&quot;date&quot;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre>
<span></span>Out[3]:
</pre></div>
</div>
<div class="output_area highlight-none notranslate"><div class="highlight"><pre>
<span></span>Text(0.5, 0, &#39;date&#39;)
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="../_images/examples_BasicDiscovery_5_1.png" src="../_images/examples_BasicDiscovery_5_1.png" />
</div>
</div>
</div>
</div>
<div class="section" id="A-more-complicated-query-which-joins-data-between-tables">
<h2>A more complicated query which joins data between tables<a class="headerlink" href="#A-more-complicated-query-which-joins-data-between-tables" title="Permalink to this headline">¶</a></h2>
<p>Imagine you want to geographically compare the average street price in
2024 between US states, and geographically visualize this.</p>
<p>This requires a query which computes the average per State and an inner
join with a table which contains the polygons of the states.</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre>
<span></span>In [4]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">sqlalchemy.sql</span> <span class="k">import</span> <span class="n">join</span><span class="p">,</span><span class="n">func</span>
<span class="k">def</span> <span class="nf">queryAveragePerState</span><span class="p">(</span><span class="n">dbcon</span><span class="p">):</span>

    <span class="c1">#find the two relevant tables</span>
    <span class="n">usw</span><span class="o">=</span><span class="n">dbcon</span><span class="o">.</span><span class="n">getTable</span><span class="p">(</span><span class="s1">&#39;usweedprices2&#39;</span><span class="p">,</span><span class="s1">&#39;public&#39;</span><span class="p">)</span>
    <span class="n">stategeo</span><span class="o">=</span><span class="n">dbcon</span><span class="o">.</span><span class="n">getTable</span><span class="p">(</span><span class="s1">&#39;ne_110m_admin_1_states_provinces&#39;</span><span class="p">,</span><span class="s1">&#39;globalgis&#39;</span><span class="p">)</span>

    <span class="c1">#create a subquery with averages per state</span>
    <span class="n">subqry1</span><span class="o">=</span><span class="n">select</span><span class="p">([</span><span class="n">usw</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">State</span><span class="p">,</span><span class="n">func</span><span class="o">.</span><span class="n">avg</span><span class="p">(</span><span class="n">usw</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">MedQ</span><span class="p">)</span><span class="o">.</span><span class="n">label</span><span class="p">(</span><span class="s2">&quot;avg&quot;</span><span class="p">)])</span><span class="o">.</span><span class="n">group_by</span><span class="p">(</span><span class="n">usw</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">State</span><span class="p">)</span><span class="o">.</span><span class="n">alias</span><span class="p">(</span><span class="s2">&quot;uswt&quot;</span><span class="p">)</span>

    <span class="c1">#join the subquery with polygon data from the stategeo table</span>
    <span class="n">j</span><span class="o">=</span><span class="n">join</span><span class="p">(</span><span class="n">subqry1</span><span class="p">,</span><span class="n">stategeo</span><span class="p">,</span><span class="n">subqry1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">State</span> <span class="o">==</span> <span class="n">stategeo</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>

    <span class="n">qry</span><span class="o">=</span><span class="n">select</span><span class="p">([</span><span class="n">subqry1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">State</span><span class="p">,</span><span class="n">subqry1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">avg</span><span class="p">,</span><span class="n">stategeo</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">geom</span><span class="p">])</span><span class="o">.</span><span class="n">select_from</span><span class="p">(</span><span class="n">j</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">dbcon</span><span class="o">.</span><span class="n">dbeng</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">qry</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="Visualize-the-result-geographically-using-matplotlib">
<h3>Visualize the result geographically using matplotlib<a class="headerlink" href="#Visualize-the-result-geographically-using-matplotlib" title="Permalink to this headline">¶</a></h3>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre>
<span></span>In [6]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">cartopy.crs</span> <span class="k">as</span> <span class="nn">ccrs</span>
<span class="kn">import</span> <span class="nn">cartopy</span>
<span class="kn">from</span> <span class="nn">geoslurp.tools.shapelytools</span> <span class="k">import</span> <span class="n">shpextract</span>
<span class="kn">from</span> <span class="nn">cartopy.feature</span> <span class="k">import</span> <span class="n">ShapelyFeature</span>


<span class="n">cmap</span> <span class="o">=</span> <span class="n">mpl</span><span class="o">.</span><span class="n">cm</span><span class="o">.</span><span class="n">viridis</span>
<span class="n">proj</span><span class="o">=</span><span class="n">ccrs</span><span class="o">.</span><span class="n">EquidistantConic</span><span class="p">(</span><span class="n">central_longitude</span><span class="o">=-</span><span class="mf">100.0</span><span class="p">,</span> <span class="n">central_latitude</span><span class="o">=</span><span class="mf">37.5</span><span class="p">,</span> <span class="n">standard_parallels</span><span class="o">=</span><span class="p">(</span><span class="mf">30.0</span><span class="p">,</span> <span class="mf">45.0</span><span class="p">))</span>
<span class="n">proj</span><span class="o">=</span><span class="n">ccrs</span><span class="o">.</span><span class="n">PlateCarree</span><span class="p">()</span>
<span class="n">mpl</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mi">7</span><span class="p">))</span>
<span class="n">ax</span> <span class="o">=</span> <span class="n">mpl</span><span class="o">.</span><span class="n">axes</span><span class="p">(</span><span class="n">projection</span><span class="o">=</span><span class="n">proj</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_extent</span><span class="p">((</span><span class="o">-</span><span class="mf">180.</span><span class="p">,</span> <span class="o">-</span><span class="mf">45.</span><span class="p">,</span> <span class="mf">20.</span><span class="p">,</span><span class="mf">75.</span><span class="p">),</span><span class="n">crs</span><span class="o">=</span><span class="n">ccrs</span><span class="o">.</span><span class="n">PlateCarree</span><span class="p">())</span>
<span class="n">background</span><span class="o">=</span><span class="n">ax</span><span class="o">.</span><span class="n">stock_img</span><span class="p">()</span>
<span class="n">background</span><span class="o">.</span><span class="n">set_alpha</span><span class="p">(</span><span class="mf">0.6</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">coastlines</span><span class="p">(</span><span class="n">linewidth</span><span class="o">=</span><span class="mf">0.3</span><span class="p">)</span>
<span class="n">minprice</span><span class="o">=</span><span class="mi">100</span>
<span class="n">maxprice</span><span class="o">=</span><span class="mi">400</span>
<span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="n">queryAveragePerState</span><span class="p">(</span><span class="n">gpcon</span><span class="p">):</span>
    <span class="n">geom</span><span class="o">=</span><span class="n">ShapelyFeature</span><span class="p">([</span><span class="n">shpextract</span><span class="p">(</span><span class="n">entry</span><span class="p">)],</span><span class="n">crs</span><span class="o">=</span><span class="n">ccrs</span><span class="o">.</span><span class="n">PlateCarree</span><span class="p">(),</span><span class="n">edgecolor</span><span class="o">=</span><span class="s1">&#39;gray&#39;</span><span class="p">,</span><span class="n">facecolor</span><span class="o">=</span><span class="n">cmap</span><span class="p">((</span><span class="n">entry</span><span class="o">.</span><span class="n">avg</span><span class="o">-</span><span class="n">minprice</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="n">maxprice</span><span class="o">-</span><span class="n">minprice</span><span class="p">)),</span><span class="n">zorder</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">add_feature</span><span class="p">(</span><span class="n">geom</span><span class="p">)</span>


<span class="n">sm</span> <span class="o">=</span> <span class="n">mpl</span><span class="o">.</span><span class="n">cm</span><span class="o">.</span><span class="n">ScalarMappable</span><span class="p">(</span><span class="n">cmap</span><span class="o">=</span><span class="n">cmap</span><span class="p">,</span><span class="n">norm</span><span class="o">=</span><span class="n">mpl</span><span class="o">.</span><span class="n">Normalize</span><span class="p">(</span><span class="n">minprice</span><span class="p">,</span><span class="n">maxprice</span><span class="p">))</span>
<span class="n">sm</span><span class="o">.</span><span class="n">_A</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">cbar</span><span class="o">=</span><span class="n">mpl</span><span class="o">.</span><span class="n">colorbar</span><span class="p">(</span><span class="n">sm</span><span class="p">,</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">orientation</span><span class="o">=</span><span class="s1">&#39;horizontal&#39;</span><span class="p">)</span>
<span class="n">cbar</span><span class="o">.</span><span class="n">set_label</span><span class="p">(</span><span class="s2">&quot;USD per ounce&quot;</span><span class="p">)</span>
<span class="n">mpl</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s2">&quot;Average US Marijuana Street price for an ounce of medium quality&quot;</span><span class="p">)</span>
<span class="n">mpl</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>

</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="../_images/examples_BasicDiscovery_9_0.png" src="../_images/examples_BasicDiscovery_9_0.png" />
</div>
</div>
</div>
</div>
</div>


           </div>
           <div class="articleComments">
            
           </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="export2Portable.html" class="btn btn-neutral float-right" title="Exporting parts of the database to portable formats" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="CreateDynDSet.html" class="btn btn-neutral" title="Download and register a dynamic dataset of (crowd-sourced?) US Marijuana street prices" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2020, Roelof Rietbroek.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../',
            VERSION:'v1.1.0',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../_static/jquery.js"></script>
      <script type="text/javascript" src="../_static/underscore.js"></script>
      <script type="text/javascript" src="../_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>